home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / mordor_2.000 / mordor_2 / src / files1.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  18KB  |  816 lines

  1. /*
  2.  * FILES1.C:
  3.  *
  4.  *    File I/O Routines.
  5.  *
  6.  *    Copyright (C) 1991, 1992, 1993 Brett J. Vickers
  7.  *
  8.  */
  9.  
  10. #include "mstruct.h"
  11. #include "mextern.h"
  12.  
  13. /**********************************************************************/
  14. /*                count_obj                  */
  15. /**********************************************************************/
  16.  
  17. /* Return the total number of objects contained within an object.  */
  18. /* If perm_only != 0, then only the permanent objects are counted. */
  19.  
  20. int count_obj(obj_ptr, perm_only)
  21. object     *obj_ptr;
  22. char     perm_only;
  23. {
  24.     otag    *op;
  25.     int    total=0;
  26.  
  27.     op = obj_ptr->first_obj;
  28.     while(op) {
  29.         if(!perm_only || (perm_only && (F_ISSET(op->obj, OPERMT))))
  30.             total++;
  31.         op = op->next_tag;
  32.     }
  33.     return(total);
  34. }
  35.  
  36. /**********************************************************************/
  37. /*                write_obj                  */
  38. /**********************************************************************/
  39.  
  40. /* Save an object to a file that has already been opened and positioned. */
  41. /* This function recursively saves the items that are contained inside   */
  42. /* the object as well.  If perm_only != 0 then only permanent objects     */
  43. /* within the object are saved with it.                     */
  44.  
  45. int write_obj(fd, obj_ptr, perm_only)
  46. int     fd;
  47. object     *obj_ptr;
  48. char     perm_only;
  49. {
  50.     int     n, cnt, cnt2=0, error=0;
  51.     otag    *op;
  52.  
  53.     n = write(fd, obj_ptr, sizeof(object));
  54.     if(n < sizeof(object))
  55.         merror("write_obj", FATAL);
  56.     
  57.     cnt = count_obj(obj_ptr, perm_only);
  58.     n = write(fd, &cnt, sizeof(int));
  59.     if(n < sizeof(int))
  60.         merror("write_obj", FATAL);
  61.  
  62.     if(cnt > 0) {
  63.         op = obj_ptr->first_obj;
  64.         while(op) {
  65.             if(!perm_only || (perm_only && 
  66.                (F_ISSET(op->obj, OPERMT)))) {
  67.                 if(write_obj(fd, op->obj, perm_only) < 0)
  68.                     error = 1;
  69.                 cnt2++;
  70.             }
  71.             op = op->next_tag;
  72.         }
  73.     }
  74.  
  75.     if(cnt != cnt2 || error)
  76.         return(-1);
  77.     else
  78.         return(0);
  79.  
  80. }
  81.  
  82. /**********************************************************************/
  83. /*                count_inv                  */
  84. /**********************************************************************/
  85.  
  86. /* Returns the number of objects a creature has in his inventory. */
  87. /* If perm_only != 0 then only those objects which are permanent  */
  88. /* will be counted.                          */
  89.  
  90. int count_inv(crt_ptr, perm_only)
  91. creature     *crt_ptr;
  92. char         perm_only;
  93. {
  94.     otag    *op;
  95.     int    total=0;
  96.  
  97.     op = crt_ptr->first_obj;
  98.     while(op) {
  99.         if(!perm_only || (perm_only && (F_ISSET(op->obj, OPERMT)))) 
  100.             total++;
  101.         op = op->next_tag;
  102.     }
  103.     return(MIN(80,total));
  104. }
  105.  
  106. /**********************************************************************/
  107. /*                write_crt                  */
  108. /**********************************************************************/
  109.  
  110. /* Save a creature to an already open and positioned file.  This function */
  111. /* also saves all the items the creature is holding.  If perm_only != 0   */
  112. /* then only those items which the creature is carrying that are       */
  113. /* permanent will be saved.                          */
  114.  
  115. int write_crt(fd, crt_ptr, perm_only)
  116. int         fd;
  117. creature     *crt_ptr;
  118. char         perm_only;
  119. {
  120.     int     n, cnt, cnt2=0, error=0;
  121.     otag    *op;
  122.  
  123.     n = write(fd, crt_ptr, sizeof(creature));
  124.     if(n < sizeof(creature))
  125.         merror("write_crt", FATAL);
  126.  
  127.     cnt = count_inv(crt_ptr, perm_only);
  128.     n = write(fd, &cnt, sizeof(int));
  129.     if(n < sizeof(int))
  130.         merror("write_crt", FATAL);
  131.  
  132.     if(cnt > 0) {
  133.         op = crt_ptr->first_obj;
  134.         while(op && cnt2<cnt) {
  135.             if(!perm_only || (perm_only && 
  136.                (F_ISSET(op->obj, OPERMT)))) {
  137.                 if(write_obj(fd, op->obj, perm_only) < 0)
  138.                     error = 1;
  139.                 cnt2++;
  140.             }
  141.             op = op->next_tag;
  142.         }
  143.     }
  144.  
  145.     if(cnt != cnt2 || error)
  146.         return(-1);
  147.     else
  148.         return(0);
  149. }
  150.  
  151. /**********************************************************************/
  152. /*                count_mon                  */
  153. /**********************************************************************/
  154.  
  155. /* Returns the number of monsters in a given room.  If perm_only is */
  156. /* nonzero, then only the number of permanent monsters in the room  */
  157. /* is returned.                                */
  158.  
  159. int count_mon(rom_ptr, perm_only)
  160. room     *rom_ptr;
  161. char     perm_only;
  162. {
  163.     ctag    *cp;
  164.     int    total=0;
  165.  
  166.     cp = rom_ptr->first_mon;
  167.     while(cp) {
  168.         if(!perm_only || (perm_only && F_ISSET(cp->crt, MPERMT)))
  169.             total++;
  170.         cp = cp->next_tag;
  171.     }
  172.     return(total);
  173. }
  174.  
  175. /**********************************************************************/
  176. /*                count_ite                  */
  177. /**********************************************************************/
  178.  
  179. /* Returns the number of items in the room.  If perm_only is nonzero */
  180. /* then only the number of permanent items in the room is returned.  */
  181.  
  182. int count_ite(rom_ptr, perm_only)
  183. room     *rom_ptr;
  184. char     perm_only;
  185. {
  186.     otag     *op;
  187.     int    total=0;
  188.  
  189.     op = rom_ptr->first_obj;
  190.     while(op) {
  191.         if(!perm_only || (perm_only && (F_ISSET(op->obj, OPERMT))))
  192.             total++;
  193.         op = op->next_tag;
  194.     }
  195.     return(total);
  196. }
  197.  
  198. /**********************************************************************/
  199. /*                count_ext                  */
  200. /**********************************************************************/
  201.  
  202. /* Returns the number of exits in the room */
  203.  
  204. int count_ext(rom_ptr)
  205. room     *rom_ptr;
  206. {
  207.     xtag    *xp;
  208.     int    total = 0;
  209.  
  210.     xp = rom_ptr->first_ext;
  211.     while(xp) {
  212.         total++;
  213.         xp = xp->next_tag;
  214.     }
  215.     return(total);
  216. }
  217.  
  218. /**********************************************************************/
  219. /*                count_ply                  */
  220. /**********************************************************************/
  221.  
  222. /* Returns the number of players in the room */
  223.  
  224. int count_ply(rom_ptr)
  225. room     *rom_ptr;
  226. {
  227.     ctag    *pp;
  228.     int    total = 0;
  229.  
  230.     pp = rom_ptr->first_ply;
  231.     while(pp) {
  232.         total++;
  233.         pp = pp->next_tag;
  234.     }
  235.     return(total);
  236. }
  237.  
  238. /**********************************************************************/
  239. /*                write_rom                  */
  240. /**********************************************************************/
  241.  
  242. /* Saves the room pointed to by rom_ptr with all its contents.  Its */
  243. /* contents include exits, descriptions, items and monsters.  If    */
  244. /* perm_only is nonzero, then only items and monsters in the room   */
  245. /* which are permanent will be saved.                    */
  246.  
  247. int write_rom(fd, rom_ptr, perm_only)
  248. int     fd;
  249. room     *rom_ptr;
  250. char     perm_only;
  251. {
  252.     int     n, cnt, error=0;
  253.     xtag    *xp;
  254.     ctag    *cp;
  255.     otag    *op;
  256.     char    pcontain;
  257.  
  258.     n = write(fd, rom_ptr, sizeof(room));
  259.     if(n < sizeof(room))
  260.         merror("write_rom", FATAL);
  261.  
  262.     cnt = count_ext(rom_ptr);
  263.     n = write(fd, &cnt, sizeof(int));
  264.     if(n < sizeof(int))
  265.         merror("write_rom", FATAL);
  266.  
  267.     xp = rom_ptr->first_ext;
  268.     while(xp) {
  269.         n = write(fd, xp->ext, sizeof(exit_));
  270.         if(n < sizeof(exit_))
  271.             merror("write_rom", FATAL);
  272.         xp = xp->next_tag;
  273.     }
  274.  
  275.     cnt = count_mon(rom_ptr, perm_only);
  276.     n = write(fd, &cnt, sizeof(int));
  277.     if(n < sizeof(int))
  278.         merror("write_rom", FATAL);
  279.  
  280.     cp = rom_ptr->first_mon;
  281.     while(cp) {
  282.         if(!perm_only || (perm_only && F_ISSET(cp->crt, MPERMT)))
  283.             if(write_crt(fd, cp->crt, 0) < 0)
  284.                 error = 1;
  285.         cp = cp->next_tag;
  286.     }
  287.  
  288.     cnt = count_ite(rom_ptr, perm_only);
  289.     n = write(fd, &cnt, sizeof(int));
  290.     if(n < sizeof(int))
  291.         merror("write_rom", FATAL);
  292.  
  293. op = rom_ptr->first_obj;
  294.         while(op) {
  295.                 if(!perm_only || (perm_only && (F_ISSET(op->obj, OPERMT)))){
  296.                         if (F_ISSET(op->obj,OCONTN)
  297.                                 && (F_ISSET(op->obj, OPERMT)))
  298.                                 pcontain =  ALLITEMS;
  299.                         else
  300.                                 pcontain = perm_only;
  301.                                 if(write_obj(fd, op->obj, pcontain) < 0)
  302.                                         error = 1;
  303.                 }
  304.                 op = op->next_tag;
  305.     }
  306.  
  307.     if(!rom_ptr->short_desc)
  308.         cnt = 0;
  309.     else
  310.         cnt = strlen(rom_ptr->short_desc) + 1;
  311.     n = write(fd, &cnt, sizeof(int));
  312.     if(n < sizeof(int))
  313.         merror("write_rom", FATAL);
  314.  
  315.     if(cnt) {
  316.         n = write(fd, rom_ptr->short_desc, cnt);
  317.         if(n < cnt)
  318.             merror("write_rom", FATAL);
  319.     }
  320.  
  321.     if(!rom_ptr->long_desc)
  322.         cnt = 0;
  323.     else
  324.         cnt = strlen(rom_ptr->long_desc) + 1;
  325.     n = write(fd, &cnt, sizeof(int));
  326.     if(n < sizeof(int))
  327.         merror("write_rom", FATAL);
  328.  
  329.     if(cnt) {
  330.         n = write(fd, rom_ptr->long_desc, cnt);
  331.         if(n < cnt)
  332.             merror("write_rom", FATAL);
  333.     }
  334.  
  335.     if(!rom_ptr->obj_desc)
  336.         cnt = 0;
  337.     else
  338.         cnt = strlen(rom_ptr->obj_desc) + 1;
  339.     n = write(fd, &cnt, sizeof(int));
  340.     if(n < sizeof(int))
  341.         merror("write_rom", FATAL);
  342.  
  343.     if(cnt) {
  344.         n = write(fd, rom_ptr->obj_desc, cnt);
  345.         if(n < cnt)
  346.             merror("write_rom", FATAL);
  347.     }
  348.  
  349.     if(error)
  350.         return(-1);
  351.     else
  352.         return(0);
  353. }
  354.  
  355. /**********************************************************************/
  356. /*                read_obj                  */
  357. /**********************************************************************/
  358.  
  359. /* Loads the object from the open and positioned file described by fd */
  360. /* and also loads every object which it might contain.  Returns -1 if */
  361. /* there was an error.                              */
  362.  
  363. int read_obj(fd, obj_ptr)
  364. int     fd;
  365. object     *obj_ptr;
  366. {
  367.     int         n, cnt, error=0;
  368.     otag        *op;
  369.     otag        **prev;
  370.     object         *obj;
  371.  
  372.     n = read(fd, obj_ptr, sizeof(object));
  373.     if(n < sizeof(object))
  374.         error = 1;
  375.  
  376.     obj_ptr->first_obj = 0;
  377.     obj_ptr->parent_obj = 0;
  378.     obj_ptr->parent_rom = 0;
  379.     obj_ptr->parent_crt = 0;
  380.     if(obj_ptr->shotscur > obj_ptr->shotsmax)
  381.         obj_ptr->shotscur = obj_ptr->shotsmax;
  382.  
  383.     n = read(fd, &cnt, sizeof(int));
  384.     if(n < sizeof(int)) {
  385.         error = 1;
  386.         cnt = 0;
  387.     }
  388.  
  389.     prev = &obj_ptr->first_obj;
  390.     while(cnt > 0) {
  391.         cnt--;
  392.         op = (otag *)malloc(sizeof(otag));
  393.         if(op) {
  394.             obj = (object *)malloc(sizeof(object));
  395.             if(obj) {
  396.                 if(read_obj(fd, obj) < 0)
  397.                     error = 1;
  398.                 obj->parent_obj = obj_ptr;
  399.                 op->obj = obj;
  400.                 op->next_tag = 0;
  401.                 *prev = op;
  402.                 prev = &op->next_tag;
  403.             }
  404.             else
  405.                 merror("read_obj", FATAL);
  406.         }
  407.         else
  408.             merror("read_obj", FATAL);
  409.     }
  410.  
  411.     if(error)
  412.         return(-1);
  413.     else
  414.         return(0);
  415. }
  416.  
  417. /**********************************************************************/
  418. /*                read_crt                  */
  419. /**********************************************************************/
  420.  
  421. /* Loads a creature from an open and positioned file.  The creature is */
  422. /* loaded at the mem location specified by the second parameter.  In   */
  423. /* addition, all the creature's objects have memory allocated for them */
  424. /* and are loaded as well.  Returns -1 on fail.                   */
  425.  
  426. int read_crt(fd, crt_ptr)
  427. int         fd;
  428. creature     *crt_ptr;
  429. {
  430.     int         n, cnt, error=0;
  431.     otag        *op;
  432.     otag        **prev;
  433.     object         *obj;
  434.  
  435.     n = read(fd, crt_ptr, sizeof(creature));
  436.     if(n < sizeof(creature))
  437.         error = 1;
  438.  
  439.     crt_ptr->first_obj = 0;
  440.     crt_ptr->first_fol = 0;
  441.     crt_ptr->first_enm = 0;
  442.     crt_ptr->first_tlk = 0;
  443.     crt_ptr->parent_rom = 0;
  444.     crt_ptr->following = 0;
  445.     for(n=0; n<20; n++)
  446.         crt_ptr->ready[n] = 0;
  447.     if(crt_ptr->mpcur > crt_ptr->mpmax)
  448.         crt_ptr->mpcur = crt_ptr->mpmax;
  449.     if(crt_ptr->hpcur > crt_ptr->hpmax)
  450.         crt_ptr->hpcur = crt_ptr->hpmax;
  451.  
  452.     n = read(fd, &cnt, sizeof(int));
  453.     if(n < sizeof(int)) {
  454.         error = 1;
  455.         cnt = 0;
  456.     }
  457.  
  458.     prev = &crt_ptr->first_obj;
  459.     while(cnt > 0) {
  460.         cnt--;
  461.         op = (otag *)malloc(sizeof(otag));
  462.         if(op) {
  463.             obj = (object *)malloc(sizeof(object));
  464.             if(obj) {
  465.                 if(read_obj(fd, obj) < 0)
  466.                     error = 1;
  467.                 obj->parent_crt = crt_ptr;
  468.                 op->obj = obj;
  469.                 op->next_tag = 0;
  470.                 *prev = op;
  471.                 prev = &op->next_tag;
  472.             }
  473.             else
  474.                 merror("read_crt", FATAL);
  475.         }
  476.         else
  477.             merror("read_crt", FATAL);
  478.     }
  479.  
  480.     if(error)
  481.         return(-1);
  482.     else
  483.         return(0);
  484. }
  485.  
  486. /**********************************************************************/
  487. /*                read_rom                  */
  488. /**********************************************************************/
  489.  
  490. /* Loads a room from an already open and positioned file into the memory */
  491. /* pointed to by the second parameter.  Also loaded are all creatures,   */
  492. /* exits, objects and descriptions for the room.  -1 is returned upon    */
  493. /* failure.                                 */
  494.  
  495. int read_rom(fd, rom_ptr)
  496. int     fd;
  497. room     *rom_ptr;
  498. {
  499.     int        n, cnt, error=0;
  500.     xtag        *xp;
  501.     xtag        **xprev;
  502.     exit_        *ext;
  503.     ctag        *cp;
  504.     ctag        **cprev;
  505.     creature    *crt;
  506.     otag        *op;
  507.     otag        **oprev;
  508.     object         *obj;
  509.     char        *sh, *lo, *ob;
  510.  
  511.     n = read(fd, rom_ptr, sizeof(room));
  512.     if(n < sizeof(room))
  513.         error = 1;
  514.  
  515.     rom_ptr->short_desc = 0;
  516.     rom_ptr->long_desc  = 0;
  517.     rom_ptr->obj_desc   = 0;
  518.     rom_ptr->first_ext = 0;
  519.     rom_ptr->first_obj = 0;
  520.     rom_ptr->first_mon = 0;
  521.     rom_ptr->first_ply = 0;
  522.  
  523.     n = read(fd, &cnt, sizeof(int));
  524.     if(n < sizeof(int)) {
  525.         error = 1;
  526.         cnt = 0;
  527.     }
  528.  
  529.     /* Load the exits */
  530.  
  531.     xprev = &rom_ptr->first_ext;
  532.     while(cnt > 0) {
  533.         cnt--;
  534.         xp = (xtag *)malloc(sizeof(xtag));
  535.         if(xp) {
  536.             ext = (exit_ *)malloc(sizeof(exit_));
  537.             if(ext) {
  538.                 n = read(fd, ext, sizeof(exit_));
  539.                 if(n < sizeof(exit_))
  540.                     error = 1;
  541.                 xp->ext = ext;
  542.                 xp->next_tag = 0;
  543.                 *xprev = xp;
  544.                 xprev = &xp->next_tag;
  545.             }
  546.             else
  547.                 merror("read_rom", FATAL);
  548.         }
  549.         else
  550.             merror("read_rom", FATAL);
  551.     }
  552.  
  553.     /* Read the monsters */
  554.  
  555.     n = read(fd, &cnt, sizeof(int));
  556.     if(n < sizeof(int)) {
  557.         error = 1;
  558.         cnt = 0;
  559.     }
  560.  
  561.     cprev = &rom_ptr->first_mon;
  562.     while(cnt > 0) {
  563.         cnt--;
  564.         cp = (ctag *)malloc(sizeof(ctag));
  565.         if(cp) {
  566.             crt = (creature *)malloc(sizeof(creature));
  567.             if(crt) {
  568.                 if(read_crt(fd, crt) < 0)
  569.                     error = 1;
  570.                 crt->parent_rom = rom_ptr;
  571.                 cp->crt = crt;
  572.                 cp->next_tag = 0;
  573.                 *cprev = cp;
  574.                 cprev = &cp->next_tag;
  575.             }
  576.             else
  577.                 merror("read_rom", FATAL);
  578.         }
  579.         else
  580.             merror("read_rom", FATAL);
  581.     }
  582.  
  583.     /* Read the items */
  584.  
  585.     n = read(fd, &cnt, sizeof(int));
  586.     if(n < sizeof(int)) {
  587.         error = 1;
  588.         cnt = 0;
  589.     }
  590.  
  591.     oprev = &rom_ptr->first_obj;
  592.     while(cnt > 0) {
  593.         cnt--;
  594.         op = (otag *)malloc(sizeof(otag));
  595.         if(op) {
  596.             obj = (object *)malloc(sizeof(object));
  597.             if(obj) {
  598.                 if(read_obj(fd, obj) < 0)
  599.                     error = 1;
  600.                 obj->parent_rom = rom_ptr;
  601.                 op->obj = obj;
  602.                 op->next_tag = 0;
  603.                 *oprev = op;
  604.                 oprev = &op->next_tag;
  605.             }
  606.             else
  607.                 merror("read_rom", FATAL);
  608.         }
  609.         else
  610.             merror("read_rom", FATAL);
  611.     }
  612.  
  613.     /* Read the descriptions */
  614.  
  615.     n = read(fd, &cnt, sizeof(int));
  616.     if(n < sizeof(int)) {
  617.         error = 1;
  618.         cnt = 0;
  619.     }
  620.  
  621.     if(cnt) {
  622.         sh = (char *)malloc(cnt);
  623.         if(sh) {
  624.             n = read(fd, sh, cnt);
  625.             if(n < cnt)
  626.                 error = 1;
  627.             rom_ptr->short_desc = sh;
  628.         }
  629.         else
  630.             merror("read_rom", FATAL);
  631.     }
  632.  
  633.     n = read(fd, &cnt, sizeof(int));
  634.     if(n < sizeof(int)) {
  635.         error = 1;
  636.         cnt = 0;
  637.     }
  638.  
  639.     if(cnt) {
  640.         lo = (char *)malloc(cnt);
  641.         if(lo) {
  642.             n = read(fd, lo, cnt);
  643.             if(n < cnt)
  644.                 error = 1;
  645.             rom_ptr->long_desc = lo;
  646.         }
  647.         else
  648.             merror("read_rom", FATAL);
  649.     }
  650.  
  651.     n = read(fd, &cnt, sizeof(int));
  652.     if(n < sizeof(int)) {
  653.         error = 1;
  654.         cnt = 0;
  655.     }
  656.  
  657.     if(cnt) {
  658.         ob = (char *)malloc(cnt);
  659.         if(lo) {
  660.             n = read(fd, ob, cnt);
  661.             if(n < cnt)
  662.                 error = 1;
  663.             rom_ptr->obj_desc = ob;
  664.         }
  665.         else
  666.             merror("read_rom", FATAL);
  667.     }
  668.  
  669.     if(error)
  670.         return(-1);
  671.     else
  672.         return(0);
  673. }
  674.  
  675. /**********************************************************************/
  676. /*                free_obj                  */
  677. /**********************************************************************/
  678.  
  679. /* This function is called to release the object pointed to by the first */
  680. /* parameter from memory.  All objects contained within it are also      */
  681. /* released from memory.  *ASSUMPTION*:  This function will only be      */
  682. /* called from free_rom() or free_crt().  Otherwise there may be      */
  683. /* unresolved links in memory which would cause a game crash.         */
  684.  
  685. void free_obj(obj_ptr)
  686. object    *obj_ptr;
  687. {
  688.     otag    *op, *temp;
  689.  
  690.     op = obj_ptr->first_obj;
  691.     while(op) {
  692.         temp = op->next_tag;
  693.         free_obj(op->obj);
  694.         free(op);
  695.         op = temp;
  696.     }
  697.     free(obj_ptr);
  698. }
  699.  
  700. /**********************************************************************/
  701. /*                free_crt                  */
  702. /**********************************************************************/
  703.  
  704. /* This function releases the creature pointed to by the first parameter */
  705. /* from memory.  All items that creature has readied or carries will     */
  706. /* also be released.  *ASSUMPTION*:  This function will only be called   */
  707. /* from free_rom().  If it is called from somewhere else, unresolved     */
  708. /* links may remain and cause a game crash.  *EXCEPTION*: This function  */
  709. /* can be called independently to free a player's information from       */
  710. /* memory (but not a monster).                         */
  711.  
  712. void free_crt(crt_ptr)
  713. creature    *crt_ptr;
  714. {
  715.     otag    *op, *tempo;
  716.     etag    *ep, *tempe;
  717.     ctag    *cp, *tempc;
  718.     ttag    *tp, *tempt;
  719.     int    i;
  720.     for(i=0; i<20; i++)
  721.         if(crt_ptr->ready[i]) {
  722.             free_obj(crt_ptr->ready[i]);
  723.             crt_ptr->ready[i] = 0;
  724.         }
  725.  
  726.     op = crt_ptr->first_obj;
  727.     while(op) {
  728.         tempo = op->next_tag;
  729.         free_obj(op->obj);
  730.         free(op);
  731.         op = tempo;
  732.     }
  733.  
  734.     cp = crt_ptr->first_fol;
  735.     while(cp) {
  736.         tempc = cp->next_tag;
  737.         free(cp);
  738.         cp = tempc;
  739.     }
  740.  
  741.     ep = crt_ptr->first_enm;
  742.     while(ep) {
  743.         tempe = ep->next_tag;
  744.         free(ep);
  745.         ep = tempe;
  746.     }
  747.  
  748.     tp = crt_ptr->first_tlk;
  749.     while(tp) {
  750.         tempt = tp->next_tag;
  751.         if(tp->key) free(tp->key);
  752.         if(tp->response) free(tp->response);
  753.         if(tp->action) free(tp->action);
  754.         if(tp->target) free(tp->target);
  755.         free(tp);
  756.         tp = tempt;
  757.     }
  758.  
  759.     del_active(crt_ptr);
  760.     free(crt_ptr);
  761. }
  762.  
  763. /**********************************************************************/
  764. /*                free_rom                  */
  765. /**********************************************************************/
  766.  
  767. /* This function releases the a room and its contents from memory.  The */
  768. /* function is passed the room's pointer as its parameter.  The exits,  */
  769. /* descriptions, objects and monsters are all released from memory.     */
  770.  
  771. void free_rom(rom_ptr)
  772. room    *rom_ptr;
  773. {
  774.     xtag     *xp, *xtemp;
  775.     otag    *op, *otemp;
  776.     ctag    *cp, *ctemp;
  777.  
  778.     free(rom_ptr->short_desc);
  779.     free(rom_ptr->long_desc);
  780.     free(rom_ptr->obj_desc);
  781.  
  782.     xp = rom_ptr->first_ext;
  783.     while(xp) {
  784.         xtemp = xp->next_tag;
  785.         free(xp->ext);
  786.         free(xp);
  787.         xp = xtemp;
  788.     }
  789.  
  790.     op = rom_ptr->first_obj;
  791.     while(op) {
  792.         otemp = op->next_tag;
  793.         free_obj(op->obj);
  794.         free(op);
  795.         op = otemp;
  796.     }
  797.  
  798.     cp = rom_ptr->first_mon;
  799.     while(cp) {
  800.         ctemp = cp->next_tag;
  801.         free_crt(cp->crt);
  802.         free(cp);
  803.         cp = ctemp;
  804.     }
  805.  
  806.     cp = rom_ptr->first_ply;
  807.     while(cp) {
  808.         ctemp = cp->next_tag;
  809.         free(cp);
  810.         cp = ctemp;
  811.     }
  812.  
  813.     free(rom_ptr);
  814.  
  815. }
  816.